package com.example.service.Imp;

import com.alibaba.fastjson.JSON;
import com.example.common.b_pojo.BAdmin;
import com.example.common.b_pojo.BAdminUser;
import com.example.dao.mapper.BAdminMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class UserDetailsServiceImp implements UserDetailsService {

    @Autowired
    private BAdminMapper bAdminMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
//        将查询出来的信息，用户信息权限信息封装到UserDetails中，
        BAdminUser adminuser = bAdminMapper.selectBAdminAndRoleAndMenuByadmin(s);
        log.info("查询用户信息：{}", JSON.toJSON(adminuser));
        if(adminuser == null || adminuser.getIsdelete() == 1){
            throw new UsernameNotFoundException("用户不存在,或者已经被禁用！");
        }
        return adminuser;
    }
}
